package com.alongthink.javademo.globalConfig;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.function.Predicate;

/**
 * swagger配置类
 *
 */
@Configuration
public class Swagger2Config {
    @Bean
    public Docket createRestApi() {
        Predicate<RequestHandler> selector2 = RequestHandlerSelectors.basePackage("com.alongthink.javademo.controller")::apply;
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket.enable(true);
        docket.apiInfo(apiInfo()).select().apis(Predicates.or(selector2::test)).paths(PathSelectors.any()).build();
        return docket;
    }

    /**
     * This is Fucking Weak headed
     *
     * @return ApiInfo
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("api文档")//设置接口文档的标题
                .description("简单优雅的restful风格：")
                .version("2.9")
                .build();
    }
}
